package org.tsinghua.answer.domain.user;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.tsinghua.answer.domain.subject.Subject;

@Entity
public class UserSubject {

	@Id
	private String id;
	@ManyToOne
	private User user;
	@ManyToOne
	private Subject subject;
	private Date createTime;
	
	public UserSubject() { }
	
	public UserSubject(User user, Subject subject) {
		setId(id);
		setUser(user);
		setSubject(subject);
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@ManyToOne
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	@ManyToOne
	public Subject getSubject() {
		return subject;
	}
	public void setSubject(Subject subject) {
		this.subject = subject;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@Transient
	public String getName() {
		if(subject != null) {
			return subject.getName();
		}
		return null;
	}
	
	@Transient
	public String getSubjectId() {
		if(subject != null) {
			return subject.getId();
		}
		return null;
	}
}
